/**
 * 
 */
package com.base.myproject.client.busi.service.assessment;

import java.util.ArrayList;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.celleditor.BaseComboBoxForm;
import com.base.myproject.client.ui.celleditor.BaseSimpleCombox;
import com.base.myproject.client.ui.celleditor.CellEditorFactory;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.HeaderGroupConfig;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.google.gwt.user.client.ui.Widget;

/**
 * 美容美发提成规则1
 * 负责对考核
 * @author zgw
 *2010-1-8
 */
public class Assessment_rule1 extends BaseJDBCPanel {

	BaseStore<BusiObject> assessment_store ;
	BaseGrid<BusiObject> assessment_grid ;
	public Assessment_rule1()
	{
		init();
	}
	public void init()
	{
		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
		centerData.setMargins(new Margins(5, 5, 0, 0));
		this.add(initWeiget(), centerData);
		
		registerMainStore(assessment_store);
		registerStore(assessment_store);
		
		
	}
	public ContentPanel initWeiget() {
	
		ContentPanel panel = new ContentPanel();
		panel.setHeaderVisible(false);
		panel.add(creategrid());

//		Button B = new Button("ddd");
//		B.addSelectionListener(new SelectionListener<ButtonEvent>(){
//
//			@Override
//			public void componentSelected(ButtonEvent ce) {
//				
////				assessment_store._commitChanges(assessment_store.getAt(0));
//				assessment_store.trySave(assessment_store.getCurcowindex());
//			}
//			
//		});
//		panel.add(B);
		panel.setSize(400, 600);
		return panel;
	}
	
	private Widget creategrid()
	{
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		
		ColumnConfig c1 = new ColumnConfig("bcode", "人员", 50);
		//TextField<String> c1text = new TextField<String>();
//		BaseSimpleCombox bsc1 =new BaseSimpleCombox("bname","bcode","");
//
//		c1.setEditor(bsc1.getCellEditor());
//		
	
		BaseComboBoxForm<BaseModelData> bsb1 = new BaseComboBoxForm<BaseModelData>("bcode","bname","bcode","",true);//new BaseComboBoxForm(CodeNameMapFactory.loadBcode_801());
		c1.setEditor(bsb1.getCelEditor());
		c1.setRenderer(bsb1);
		
		
		ColumnConfig c2 = new ColumnConfig("systemid", "店名", 50);
		
//		BaseSimpleCombox bsc2 =new BaseSimpleCombox("name","SystemInfo","");
//		c2.setEditor(bsc2.getCellEditor());
		
		BaseComboBoxForm<BaseModelData> bsb2 = new BaseComboBoxForm<BaseModelData>("id","name","systeminfo","",true);//new BaseComboBoxForm(CodeNameMapFactory.loadBcode_801());
		c2.setEditor(bsb2.getCelEditor());

		c2.setRenderer(bsb2);
		
		ColumnConfig c3 = new ColumnConfig("service", "服务类型", 50);
		BaseSimpleCombox bsc3 =new BaseSimpleCombox("service","s_service","");
		c3.setEditor(bsc3.getCellEditor());
		
		
		//---
//		
//		BaseComboBoxForm<BaseModelData> dd = new BaseComboBoxForm<BaseModelData>("bcode","bname","bcode","",true);//new BaseComboBoxForm(CodeNameMapFactory.loadBcode_801());
//		c3.setEditor(dd.getCelEditor());
//
//		c3.setRenderer(dd);
		//---
		
		ColumnConfig c4 = new ColumnConfig("method1", "指定", 50);
//		TextField<String> c4text = new TextField<String>();
		NumberField c4text = new NumberField();
		//c4.setNumberFormat(NumberFormat.getFormat("0"));
		c4.setEditor(new CellEditor(c4text));
		
		ColumnConfig c5 = new ColumnConfig("method2", "轮牌", 50);
		NumberField c5text = new NumberField();
		//c5.setNumberFormat(NumberFormat.getFormat("0"));
		c5.setEditor(new CellEditor(c5text));
		
		ColumnConfig c7 = new ColumnConfig("method3", "开发", 50);
		NumberField c7text = new NumberField();
		//c7.setNumberFormat(NumberFormat.getFormat("0"));
		c7.setEditor(new CellEditor(c7text));
		
//		ColumnConfig c8 = new ColumnConfig("method4", "轮牌", 50);
//		NumberField c8text = new NumberField();
//		c8.setNumberFormat(NumberFormat.getFormat("0%"));
//		c8.setEditor(new CellEditor(c8text));
//		
//		ColumnConfig c9 = new ColumnConfig("method5", "开发", 50);
//		NumberField c9text = new NumberField();
//		c9.setNumberFormat(NumberFormat.getFormat("0%"));
//		c9.setEditor(new CellEditor(c9text));
//		
//		ColumnConfig c10 = new ColumnConfig("method6", "指定", 50);
//		NumberField c10text = new NumberField();
//		c10.setNumberFormat(NumberFormat.getFormat("0%"));
//		c10.setEditor(new CellEditor(c10text));
//		
//
//		
//		ColumnConfig c12 = new ColumnConfig("method7", "开发", 50);
//		NumberField c12text = new NumberField();
//		c12.setNumberFormat(NumberFormat.getFormat("0%"));
//		c12.setEditor(new CellEditor(c12text));
//		
//		ColumnConfig c13 = new ColumnConfig("method8", "轮牌", 50);
//		NumberField c13text = new NumberField();
//		c13.setNumberFormat(NumberFormat.getFormat("0%"));
//		c13.setEditor(new CellEditor(c13text));
//		
//		ColumnConfig c14 = new ColumnConfig("method9", "指定", 50);
//		NumberField c14text = new NumberField();
//		c14.setNumberFormat(NumberFormat.getFormat("0%"));
//		c14.setEditor(new CellEditor(c14text));
		
		ColumnConfig c15 = new ColumnConfig("groupicode", "身份", 50);
		BaseComboBoxForm<BaseModelData> bsb15 = new BaseComboBoxForm<BaseModelData>("groupicode","groupname","basegroup","",true);//new BaseComboBoxForm(CodeNameMapFactory.loadBcode_801());
		c15.setEditor(bsb15.getCelEditor());

		c15.setRenderer(bsb15);
		
		
		CellEditorFactory cef = new CellEditorFactory();
		ColumnConfig c16 = new ColumnConfig("methodse", "方式", 50);
//		BaseSimpleCombox bsc3 =new BaseSimpleCombox("service","s_service","");
		c16.setEditor(cef.getassessCellEditor());
		
		
		columns.add(c2);
		columns.add(c1);
		
		columns.add(c15);
		columns.add(c3);
		columns.add(c16);
		columns.add(c4);
		columns.add(c5);
		
		columns.add(c7);
//		columns.add(c8);
//		columns.add(c9);
//		columns.add(c10);
//
//		columns.add(c12);
//		columns.add(c13);
//		columns.add(c14);
		
		
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");

		type.addField("icode");

		type.addField("bcode");
		type.addField("systemid");
		type.addField("service");
		type.addField("groupicode");
		type.addField("methodse");
		type.addField("method1");
		type.addField("method2");
		type.addField("method3");
//		type.addField("method4");
//		type.addField("method5");
//		type.addField("method6");
//		type.addField("method7");
//		type.addField("method8");
//		type.addField("method9");
		
		
		StoreInfo info = new StoreInfo();

		info.setTablename("assessment");
		info.setSql("select * from assessment");
		info.setKeyname(new String[] { "icode" });
		
		assessment_store = new BaseStore<BusiObject>(type, info);
		assessment_store.setName("assessment");
		
		ColumnModel cm = new ColumnModel(columns);
		
		 cm.addHeaderGroup(0, 2, new HeaderGroupConfig("", 1, 5)); 
		 cm.addHeaderGroup(0, 7, new HeaderGroupConfig("实收金额比例", 1, 3)); 
//		 cm.addHeaderGroup(0, 9, new HeaderGroupConfig("应收金额比例1", 1, 3));
//		 cm.addHeaderGroup(0,12, new HeaderGroupConfig("固定金额", 1, 3));
//		 cm.addHeaderGroup(0, 3, new HeaderGroupConfig("按照比例", 1, 3));
//		 cm.addHeaderGroup(0, 3, new HeaderGroupConfig("按照比例", 1, 3));
//		 
//		 cm.addHeaderGroup(1, 2, new HeaderGroupConfig("a", 10, 12)); 
		 assessment_grid = new BaseGrid<BusiObject>(assessment_store, cm);
//		assessment_grid.setAutoHeight(true);
		assessment_grid.setHeight(300);
//		assessment_grid.setAutoWidth(true);
//		assessment_grid.setSize(400, 400);
		assessment_grid.getView().setForceFit(true);
		cbs.setSelectionMode(SelectionMode.SINGLE);
		assessment_grid.setSelectionModel(cbs);
		return assessment_grid;
	}
}
